package cn.maxhou.service.impl;

import cn.maxhou.dao.PetDao;
import cn.maxhou.dao.impl.PetDaoMySQLImpl;
import cn.maxhou.entity.Pet;
import cn.maxhou.service.PetService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service("petService")
public class PetServiceImpl implements PetService {
    @Resource(type=PetDaoMySQLImpl.class)
    PetDao petDao;
    @Override
    public boolean save(Pet pet) {
        int rows= petDao.insert(pet);
        if(true){
            //模拟业务执行过程中出现异常
            throw  new RuntimeException("业务操作异常!");
        }
        return rows>0;
    }

    @Override
    public boolean modify(Pet pet) {
        delay(2000);
        return false;
    }

    @Override
    public boolean delete(Integer id) {
        delay(1000);
        return false;
    }

    //模拟业务执行所需的时间
    private void delay(int time) {
        try{
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
